import Events from "./commonEvents"
export function getPropsList(attr = []){
  const props = {}
  attr.forEach(item => {
    props[item.fieldName] = {
      type: item.dataType,
      default: item.initialValue,
      require: !!item.require
    }
  })
  return props
}

export function styleFilter(style){
  return {
    width: "100%",
    height: "100%",
    // ...style,
    // width: style.width + style.widthUnit,
    // height: style.height + style.heightUnit,
    // fontSize: `${style.fontSize  }px`,
    // fontWeight: `${style.fontWeight  }`,
    // lineHeight: style.lineHeight + style.lineHeightUnit,
    // borderWidth: style.borderWidth + style.borderWidthUnit,
  }
}

/**
 * 设置组件的显示隐藏
 * @returns
 */
export function show(){
  const {
    tabsId,
    tabId
  } = this
  const {
    canvasComponentList
  } = this.$store.state.lowCode
  if (tabsId && tabId){
    const item = canvasComponentList.find(item => item.tag === 'c-tabs' && item.props.tabsId === tabsId && item.props.id === tabId)
    return !!item
  }
  else {
    return true
  }
}

/**
 * 封装events对象,为handle添加vue实例对象
 * @returns
 */
export function setEventVm(events, vm){
  const handleList = {}
  Object.keys(events).forEach(key => {
    const handleName = events[key]
    handleList[key] = (event, ...args) => {
      return Events[handleName].call(event, vm, ...args)
    }

    // const handle = Events[events[key]]
    // events[key] = (...args)=> {
    //   return handle(vm, ...args)
    // }
  })
  return handleList
}
